/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * auxCitas.java
 *
 * Created on Jan 15, 2011, 11:56:42 PM
 */

package GUI.clinica;

import java.text.SimpleDateFormat;
import java.util.Date;
import Persistencia.*;;
import cprincipal.*;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import GUI.*;

/**
 *
 * @author RafaelGutierrez
 */
public class auxCitas extends javax.swing.JFrame {
    CitaXmlClinica citas = new CitaXmlClinica();
    

    /** Creates new form auxCitas */
    public auxCitas() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        TxtCedulaPaciente = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        ComboBoxHora = new javax.swing.JComboBox();
        BotonAceptar = new javax.swing.JButton();
        BotonRegresar = new javax.swing.JButton();
        jDateChooser1 = new com.toedter.calendar.JDateChooser();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Indique Cedula Paciente");

        jLabel2.setText("Indique Fecha de Cita");

        jLabel3.setText("Indique Hora de Consulta");

        ComboBoxHora.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "-", "7:00 am", "8:00 am", "9:00 am", "10:00 am", "11:00 am", "12:00 pm", "1:00 pm", "2:00 pm", "3:00 pm", "4:00 pm", "5:00 pm", "6:00 pm ", "7:00 pm", "8:00 pm", "9:00 pm ", "10:00 pm", "11:00 pm", "12:00 am", "1:00 am", "2:00 am", "3:00 am", "4:00 am", "5:00 am", "6:00 am" }));

        BotonAceptar.setText("Aceptar");
        BotonAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BotonAceptarActionPerformed(evt);
            }
        });

        BotonRegresar.setText("Regresar");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(113, 113, 113)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(jLabel3)
                            .add(jLabel2)
                            .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                                .add(TxtCedulaPaciente)
                                .add(jLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(ComboBoxHora, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(jDateChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                    .add(layout.createSequentialGroup()
                        .add(85, 85, 85)
                        .add(BotonAceptar)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(BotonRegresar)))
                .addContainerGap(119, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(35, 35, 35)
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(TxtCedulaPaciente, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(jLabel2)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jDateChooser1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jLabel3)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(ComboBoxHora, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(BotonAceptar)
                    .add(BotonRegresar))
                .addContainerGap(35, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BotonAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BotonAceptarActionPerformed
        // TODO add your handling code here:
        Date fecha = new Date();

        fecha = jDateChooser1.getDate();

        SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");

        String fechaString = formatoFecha.format(fecha).toString();

        String horaString = ComboBoxHora.getSelectedItem().toString();

        //citas.buscarCita(Integer.parseInt(TxtCedulaPaciente.getText()),fechaString,horaString);

        if ((citas.buscarCita(Integer.parseInt(TxtCedulaPaciente.getText()),fechaString,horaString))!=null){
            Citas cita = new Citas();
            cita = citas.buscarCita(Integer.parseInt(TxtCedulaPaciente.getText()), fechaString, horaString);
            JFrame parent = new JFrame();
            String multiLineMsg[] = { "Bienvenido: ",cita.getNombrepaciente()+" ","Ingrese a consulta con el doctor  "+cita.getNombredoctor()};
            JOptionPane.showMessageDialog(parent, multiLineMsg);
            this.dispose();
            informeConsulta ventana = new informeConsulta(cita);
                    ventana.setVisible(true);
            HistorialMedico historial = new HistorialMedico();
            historial.setCedulapaciente(cita.getCedulapaciente());
            historial.setFechaconsulta(cita.getFecha());
            historial.setHora(cita.getHora());
            historial.setNombremedico(cita.getNombredoctor());
          /*  Object[] options = {"Yes, please",
                    "No, thanks",
                    "No eggs, no ham!"};
int n = JOptionPane.showOptionDialog(frame,
    "Would you like some green eggs to go "
    + "with that ham?",
    "A Silly Question",
    JOptionPane.YES_NO_CANCEL_OPTION,
    JOptionPane.QUESTION_MESSAGE,
    null,
    options,
    options[2]);  */
        }else{
             JOptionPane.showMessageDialog(null, "Cita no registrada", "error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_BotonAceptarActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new auxCitas().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BotonAceptar;
    private javax.swing.JButton BotonRegresar;
    private javax.swing.JComboBox ComboBoxHora;
    private javax.swing.JTextField TxtCedulaPaciente;
    private com.toedter.calendar.JDateChooser jDateChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables

}
